# -*- coding:utf-8 -*-
# CREATED BY: jiangbohuai
# CREATED ON: 2021/4/17 10:08 PM
# LAST MODIFIED ON:
# AIM:

import numpy as np
from model.distences_formular import euclidean_distance
from model.vectors import taxicab_norm


def get_fuzzy_similarity(data: np.ndarray) -> np.ndarray:
    m, n = np.shape(data)
    r_ij = []
    for i in range(n):
        r_j = []
        for j in range(n):
            x_i = data[:, i]
            y_j = data[:, j]
            r_j.append(1 - 1 / m * (euclidean_distance(x_i, y_j)))
        print(r_j)
        r_ij.append(r_j)
    return np.array(r_ij)


def get_fuzzy_disition(fuzzy_simil_matrix: np.ndarray, labels: np.ndarray):
    D = labels.reshape(-1)
    RA = fuzzy_simil_matrix
    # -- get U/D -- #
    U_D = dict()
    for i, label in enumerate(D):
        U_D.setdefault(label, []).append(RA[:, i:i + 1])

    # -- get ~D -- #
    D_hat = []
    for value in U_D.values():
        x_a_and_D_i = taxicab_norm(np.hstack(value), axis=1)
        x_a_norm = taxicab_norm(RA, axis=1)
        D_hat.append(x_a_and_D_i / x_a_norm)
    return np.transpose(D_hat)


def get_fuzzy_lower_bounds(R_matrix: np.ndarray, D_hat: np.ndarray):
    m, n = D_hat.shape
    R_minus = 1 - R_matrix
    for i in range(n):
        Di = D_hat[:, i]
        middle_res = np.max(np.vstack([Di,R_minus]),axis=0,keepdims=True)
        DiX1 = np.min(x1)
        print()